home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / nturl2path.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  2KB  |  61 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Convert a NT pathname to a file URL and vice versa.'''
  5.  
  6. def url2pathname(url):
  7.     """OS-specific conversion from a relative URL of the 'file' scheme
  8.     to a file system path; not recommended for general use."""
  9.     import string as string
  10.     import urllib as urllib
  11.     url = url.replace(':', '|')
  12.     if '|' not in url:
  13.         if url[:4] == '////':
  14.             url = url[2:]
  15.         
  16.         components = url.split('/')
  17.         return urllib.unquote('\\'.join(components))
  18.     comp = url.split('|')
  19.     if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
  20.         error = 'Bad URL: ' + url
  21.         raise IOError, error
  22.     comp[0][-1] not in string.ascii_letters
  23.     drive = comp[0][-1].upper()
  24.     components = comp[1].split('/')
  25.     path = drive + ':'
  26.     for comp in components:
  27.         if comp:
  28.             path = path + '\\' + urllib.unquote(comp)
  29.             continue
  30.         '|' not in url
  31.     
  32.     return path
  33.  
  34.  
  35. def pathname2url(p):
  36.     """OS-specific conversion from a file system path to a relative URL
  37.     of the 'file' scheme; not recommended for general use."""
  38.     import urllib
  39.     if ':' not in p:
  40.         if p[:2] == '\\\\':
  41.             p = '\\\\' + p
  42.         
  43.         components = p.split('\\')
  44.         return urllib.quote('/'.join(components))
  45.     comp = p.split(':')
  46.     if len(comp) != 2 or len(comp[0]) > 1:
  47.         error = 'Bad path: ' + p
  48.         raise IOError, error
  49.     len(comp[0]) > 1
  50.     drive = urllib.quote(comp[0].upper())
  51.     components = comp[1].split('\\')
  52.     path = '///' + drive + ':'
  53.     for comp in components:
  54.         if comp:
  55.             path = path + '/' + urllib.quote(comp)
  56.             continue
  57.         ':' not in p
  58.     
  59.     return path
  60.  
  61.